package org.example.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/chat")
public class ChatClientController {
    private final ChatClient chatClient;
    public ChatClientController(ChatClient chatClient) {
        this.chatClient = chatClient;
    }
    @RequestMapping("/call")
    public String call(String message){
        return chatClient.prompt(message).call().content();
    }
    @RequestMapping(value = "/stream", produces = "text/html;charset=utf-8")
    public Flux< String> stream(String message){
        return chatClient.prompt(message).stream().content();
    }
}
